package com.example.avmanagerweb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.avmanagerweb.entity.SysDepartment;
import com.example.avmanagerweb.entity.SysUserinfo;
import com.example.avmanagerweb.mapper.SysUserinfoMapper;
import com.example.avmanagerweb.result.exceptionhandler.JWException;
import com.example.avmanagerweb.service.SysUserinfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xg
 * @since 2023-08-16
 */
@Service
public class SysUserinfoServiceImpl extends ServiceImpl<SysUserinfoMapper, SysUserinfo> implements SysUserinfoService {

    @Override
    @Transactional(propagation = Propagation.NESTED, isolation = Isolation.DEFAULT)
    public boolean removeList(List<SysDepartment> departmentList, List<Integer> listByIds) {
        List<SysUserinfo> sysUserinfos = this.listByIds(listByIds);
        if(sysUserinfos == null || sysUserinfos.size() <= 0){
            throw new JWException(500,"批量删除 用户查询不到");
        }
        boolean fla = true;
        for (SysUserinfo userinfo : sysUserinfos) {

            if(userinfo == null){
                continue;
            }
            fla = true;
            for (SysDepartment sysDepartment : departmentList) {
                System.out.println( sysDepartment.getDepid() +"=="+ userinfo.getUdepid()+ "   测试" );
                if(sysDepartment.getDepid() == userinfo.getUdepid()){
                    fla = false;
                    break;
                }
            }
            if(fla) {
                throw new JWException(500,"批量删除 禁止跨组删除");
            }
        }
        boolean remove = this.removeByIds(listByIds);
        return remove;
    }
}
